package com.wicket.okrpbff.biz.service.impl;

import cn.hutool.core.bean.BeanUtil;
import com.wicket.okrpbff.biz.service.OrgDictionaryService;
import com.wicket.okrpbff.biz.service.dto.req.*;
import com.wicket.okrpbff.biz.service.dto.res.*;
import com.wicket.okrpbff.common.ro.OkrResult;
import com.wicket.okrpbff.common.ro.OkrResult;
import com.wicket.okrpbff.common.util.CommonFunctionHelper;
import com.wicket.okrpbff.common.util.RedisUtil;
import javax.annotation.Resource;
import org.apache.skywalking.apm.toolkit.trace.Tag;
import org.apache.skywalking.apm.toolkit.trace.Tags;
import org.apache.skywalking.apm.toolkit.trace.Trace;
import org.springframework.stereotype.Service;
import com.wicket.okrframework.integration.FwBaseOrgDictionaryClient;
import com.wicket.okrframework.integration.dto.QueryTaskCategoriesListComRespDto;
import com.wicket.okrframework.integration.dto.QueryTaskCategoriesListComReqDto;
import com.wicket.okrpbff.biz.service.dto.common.BffTaskCategoriesDto;
import com.wicket.okrpbff.common.dto.TreeNode;
import java.util.ArrayList;
import java.util.stream.Collectors;
import java.util.List;
import com.wicket.okrpbff.common.exception.Assert;

/**
 * @author ：
 * @date ：
 *
 * 
 * @version 1.0
 */
@Service
public class OrgDictionaryServiceImpl implements OrgDictionaryService {

  @Resource
  private RedisUtil redisUtil;
@Resource
  FwBaseOrgDictionaryClient fwBaseOrgDictionaryClient;
/**
   * B1查询任务分类列表(边界)[10248]
   * gen by moon at 10/3/2024, 2:26:38 PM
   */
    @Trace(operationName = "B1查询任务分类列表(边界)")
    @Tags({@Tag(key = "参数",value = "arg[0]"),
            @Tag(key = "返回值",value = "returnedObj")})
  @Override
  public BffQueryTaskCategoriesListBorderRespDto queryTaskCategoriesListBorder(BffQueryTaskCategoriesListBorderReqDto reqDto){
      
       
       QueryTaskCategoriesListComRespDto queryTaskCategoriesListComRespDto_1 =null;
//步骤0: D1查询任务分类列表(公共) - queryTaskCategoriesListCom
     QueryTaskCategoriesListComRespDto queryTaskCategoriesListComRespDto = null;
    QueryTaskCategoriesListComReqDto queryTaskCategoriesListComReqDto=new QueryTaskCategoriesListComReqDto();
  queryTaskCategoriesListComReqDto.setIsSystemData("FALSE");//sourceId:2012911_1
queryTaskCategoriesListComReqDto.setSubjectLifeCycle("CURRENTLY_VALID");//sourceId:2012915_1
queryTaskCategoriesListComReqDto.setSpaceId(CommonFunctionHelper.getBaseInfoFromLocal().getSpecSpaceId());//CURRENT_SPACEID//sourceId:2012916_1
if(reqDto!=null){
      queryTaskCategoriesListComReqDto.setParentTypeDictionaryCode(reqDto.getParentTypeDictionaryCode());//SimpleFieldAssign//sourceId:2012923_1
queryTaskCategoriesListComReqDto.setTypeDictionaryName(reqDto.getTypeDictionaryName());//SimpleFieldAssign//sourceId:2012909_1
queryTaskCategoriesListComReqDto.setThemeCode(reqDto.getThemeCode());//SimpleFieldAssign//sourceId:2012912_1
    }
  
    /*D1查询任务分类列表(公共)[10030]   */
    Assert.isNull(queryTaskCategoriesListComReqDto.getThemeCode(),"B1查询任务分类列表(边界)-D1查询任务分类列表(公共)-主题标识不能为空",false);
Assert.isNull(queryTaskCategoriesListComReqDto.getIsSystemData(),"B1查询任务分类列表(边界)-D1查询任务分类列表(公共)-是否系统数据不能为空",false);
Assert.isNull(queryTaskCategoriesListComReqDto.getSpaceId(),"B1查询任务分类列表(边界)-D1查询任务分类列表(公共)-创建于空间ID不能为空",false);
      queryTaskCategoriesListComRespDto = fwBaseOrgDictionaryClient.queryTaskCategoriesListCom(queryTaskCategoriesListComReqDto).getData()/*vcase invoke 跨dubbo调用;*/;
      
      
      queryTaskCategoriesListComRespDto_1 = queryTaskCategoriesListComRespDto;
    
BffQueryTaskCategoriesListBorderRespDto retData = new BffQueryTaskCategoriesListBorderRespDto();
  if(queryTaskCategoriesListComRespDto_1!=null){
      retData.setTaskCategoriesList(queryTaskCategoriesListComRespDto_1.getTaskCategoriesList().stream().map(item -> BeanUtil.toBean(item, BffTaskCategoriesDto.class)).collect(Collectors.toList()));//objList-to-objLists//sourceId:2012922_1
    }
  

      List<Object> allNodes =new ArrayList<>();
      allNodes.addAll(retData.getTaskCategoriesList());
     List<TreeNode> nodeList = CommonFunctionHelper.buildTree(allNodes);
     retData.setTreeNode(nodeList);
     retData.setTaskCategoriesList(null);
    
return retData;
  }
  //
}
